package com.wangh.xsap.controller;

import com.wangh.xsap.vo.EmployeeVO;
import  com.wangh.xsap.utils.common.R;
import com.wangh.xsap.service.LoginService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：wangh
 * @Description 描述该类的功能
 * @name：LoginController
 * @Date：2025/5/28 16:33
 */
@RestController
@RequestMapping("/login")
@Slf4j
public class LoginController {
    private LoginService loginService;

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }
//    用户登录的方法
    @PostMapping()
    public R login(@RequestBody EmployeeVO employeeVO, HttpSession session) {
       String code = (String) session.getAttribute("verifyCode");
       if(employeeVO.getCaptcha().equals(code)){
           log.info("===>{}",employeeVO);
           return loginService.login(employeeVO);
       }else {
           return  R.error("验证码错误");
       }

    }

}
